#include<iostream>
#include<algorithm>
using namespace std;
const int N = 410;
int arr[N];
int s[N];
int f[N][N];
int g[N][N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i + n] = s[i];
	}
	for (int i = 1; i <= 2 * n; i++) {
		s[i] += s[i - 1];
		//cout << s[i] << " ";
	}
	for (int len = 1; len <= n; len++) {
		for (int l = 1; l + len - 1 <= n * 2; l++) {
			int r = l + len - 1;
			if (len == 1)f[l][r] = 0, g[l][r] = 0;
			else {
				f[l][r] = 1e9;
				g[l][r] = -1e9;
				for (int k = l; k < r; k++) {
					f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]);
					g[l][r] = max(g[l][r], g[l][k] + g[k + 1][r] + s[r] - s[l - 1]);
				}
			}
		}
	}
	int mi = 1e9, ma = -1e9;
	for (int i = 1; i <= n; i++) {
		mi = min(mi, f[i][i + n - 1]);
		ma = max(ma, g[i][i + n - 1]);
	}
	cout << mi << endl;
	cout << ma << endl;
	return 0;
}